package com.postek.coyote.postekwifi;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.postek.cdf.CDFPTKAndroid;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2017/8/8 0008.
 */

public class SentPPLE extends AppCompatActivity {
private Button clean=null;
private Button sentPPLE=null;
private EditText editText=null;
private CDFPTKAndroid cdf = MainActivity.cdf;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pple);
        clean= (Button) findViewById(R.id.clean);
        sentPPLE= (Button) findViewById(R.id.sent);
        editText= (EditText) findViewById(R.id.pple);
        clean.setOnClickListener(cleanText);

        sentPPLE.setOnClickListener(sent);
    }
    View.OnClickListener cleanText=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          editText.setText("");
        }
    };
    View.OnClickListener sent=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String content=editText.getText().toString();
            String newString=null;
            Pattern p=Pattern.compile("\n");
            Matcher m=p.matcher(content);
            if (m.find()){
                 newString=m.replaceAll("\r\n");
            }
           int  nReturn=cdf.PTK_OutputByOrder(newString);
        if (nReturn==0){
            Toast.makeText(SentPPLE.this,"发送成功",Toast.LENGTH_SHORT).show();
            Log.e("发送数据",editText.getText().toString());
        }
        }
    };
}
